
#include "task_modbus.h"


uint16_t xx=0;

void Task_ModbusSend(void * pvParameters)
{
	struct _SM_STRUCTURE buff={0};
	for(;;)
	{
		uint8_t i=3;
		vTaskDelay(20/portTICK_PERIOD_MS);
		if(xQueueReceive(pQueue_SM_Msg,&buff,0))
		{
			uint8_t x=SM_SendMessage((uint8_t *)&buff,buff.rx_enum,buff.waittime);
			if(x==1)
			{
				printf("SM Commication error\r\n");
			}
			else if(x==2)
			{
				printf("SM Commication Time Out\r\n");
			}
		}
	}
}

void Task_ModbusRecieve(void * pvParameters)
{
	for(;;)
	{
		vTaskDelay(10/portTICK_PERIOD_MS);
		if(USART_SM_Message.usart_sm_rec_flag ==1)
		{

#if defined debug
			printf("SM RX=");
			for(uint8_t i=0 ; i<USART2_Message.usart2_rec_len ; i++)
			{
				if(USART2_Message.USART2_RX_Buffer[i]<=0x0F)
					printf("0");
				printf("%X",USART2_Message.USART2_RX_Buffer[i]);
			}
			printf("\r\n");
#endif
			uint8_t * dd = FindstrDDDD(USART_SM_Message.USART_SM_RX_Buffer);
			if(dd !=NULL)
				SM_AnalyizeData(dd);
			
			memset(USART_SM_Message.USART_SM_RX_Buffer,0,125);
			USART_SM_Message.usart_sm_rec_flag=0;
		}
	}
}



